﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using PropertyManagment.config;
using PropertyManagment.entity;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

namespace PropertyManagment.mapper.impl {

    public class SysMenuMapperImpl : BaseMapperImpl<SysMenu>,SysMenuMapper {

        private readonly DbSet<SysUserRole> sysUserRoles;
        private readonly DbSet<SysRoleMenu> sysRoleMenus;
        private readonly DbSet<SysRole> sysRole;

        public SysMenuMapperImpl(AppDbContext context) : base(context) {
            sysUserRoles = context.Set<SysUserRole>();
            sysRoleMenus = context.Set<SysRoleMenu>();
            sysRole = context.Set<SysRole>();
        }
        public List<long> getMenuIdByUserId(long userId) {
            var query = from ur in sysUserRoles
                         join r in sysRole on ur.role_id equals r.id
                         join rm in sysRoleMenus on ur.role_id equals rm.role_id
                         where ur.user_id == userId & r.statu != 0
                         select rm.menu_id;

            List<long> list = query.Distinct().ToList();
            return list;
        }
    }
}
